package com.zhuojy.equity.mall.admin.service.record;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuojy.equity.mall.admin.common.entity.po.record.TRecordPO;
import com.zhuojy.equity.mall.admin.common.pojo.ResultEntity;
import com.zhuojy.equity.mall.admin.dal.mapper.record.RecordMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author xrz
 * @version 1.0
 * @description:TODO
 * @date 2024/4/15 16:33
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RecordService extends ServiceImpl<RecordMapper, TRecordPO> {
    public ResultEntity findrecordPagination(TRecordPO tCarMaintainPO, Integer pageSize, Integer pageNum) {
        Page<TRecordPO> page = new Page<>(pageNum, pageSize);
        IPage<TRecordPO> tCarMaintainPOIPage = this.baseMapper.findrecordPagination(tCarMaintainPO, page);
        return ResultEntity.OK(tCarMaintainPOIPage);
    }

    public ResultEntity addrecord(TRecordPO tCarEtcConsumePO) {
        tCarEtcConsumePO.setCreateTime(new Date());
        this.baseMapper.insert(tCarEtcConsumePO);
        return ResultEntity.OK("添加成功");
    }

    public ResultEntity uprecord(TRecordPO tCarEtcConsumePO) {
        tCarEtcConsumePO.setUpdateTime(new Date());
        this.updateById(tCarEtcConsumePO);
        return ResultEntity.OK("修改成功");
    }

    public ResultEntity echorecord(Integer id) {
        TRecordPO tRecordPO = this.baseMapper.selectById(id);
        return ResultEntity.OK(tRecordPO);
    }

    public ResultEntity delrecord(Integer id) {
        this.baseMapper.deleteById(id);
        return ResultEntity.OK("操作成功");
    }

    public ResultEntity findselect() {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.select("id","record_id","record_name","record_company");
        List<TRecordPO> list = this.baseMapper.selectList(wrapper);
        return ResultEntity.OK(list);
    }
}
